var e = require("../../utils/network.js"), t = require("../../model/awconfig.js");

Page({
    data: {
        count: 5,
        postion: 1,
        way: 3,
        words: "我喜欢你",
        header_title: "西瓜工具",
        currentPoem: "我欲渡河水,喜甘棠翠荫,欢会方别离,你看那梨花",
        poemArrays: [ "我欲渡河水", "喜甘棠翠荫", "欢会方别离", "你看那梨花" ]
    },
    onLoad: function(e) {
        var a = this;
        t.registerConfigCallback(function() {
            a.awconfigSuccessCallback();
        }, function(e) {}), a.awconfigSuccessCallback();
    },
    awconfigSuccessCallback: function() {
        var e = wx.getStorageSync("appConfig");
        "M_KuaiDou" == getApp().globalData.appName && this.setData({
            header_title: "快抖工具箱"
        }), null != e.header_title && this.setData({
            header_title: e.header_title
        });
    },
    onShareAppMessage: function() {},
    bindCountChange: function(e) {
        this.setData({
            count: e.detail.value
        });
    },
    bindPositionChange: function(e) {
        this.setData({
            postion: e.detail.value
        });
    },
    bindWayChange: function(e) {
        this.setData({
            way: e.detail.value
        });
    },
    inputChange: function(e) {
        console.log(e.detail.detail.value), this.setData({
            words: e.detail.detail.value
        });
    },
    handleClickBuild: function(t) {
        var a = this;
        if (null != a.data.words && "" != a.data.words) if (0 != (o = a.data.words, new RegExp("[\\u4E00-\\u9FFF]+", "g").test(o))) {
            var o;
            wx.showLoading({
                title: "作诗中..."
            });
            "https://poem.fccabc.com/poem";
            var n = {
                words: a.data.words,
                mode: a.data.postion,
                length: a.data.count,
                yayun: a.data.way
            };
            (0, e.get)("https://poem.fccabc.com/poem", n).then(function(e) {
                if (1 == e.code) {
                    String.prototype.replaceAll = function(e, t) {
                        return regExp = new RegExp(e, "g"), this.replace(regExp, t);
                    }, wx.hideLoading();
                    var t = "";
                    console.log(e.content), e.content ? t = e.content[0] : e.data && (t = e.data[0]);
                    var o = (t = (t = t.replace(/，/g, "\n")).replace(/。/g, "\n")).split(",");
                    a.setData({
                        currentPoem: t,
                        poemArrays: o
                    });
                } else if (1001 == e.code) {
                    if (null != e.errorMessage) "model" == e.errorAlertType ? wx.showModal({
                        title: "提示",
                        content: e.errorMessage,
                        showCancel: !1
                    }) : wx.showToast({
                        title: e.errorMessage
                    });
                    wx.hideLoading();
                } else 1002 == e.code || wx.showModal({
                    title: "错误信息",
                    content: "处理失败，请稍后再试。",
                    showCancel: !1
                }), wx.hideLoading();
            }).catch(function(e) {
                wx.hideLoading();
            });
        } else wx.showToast({
            title: "只能输入汉字"
        }); else wx.showToast({
            title: "请输入文字"
        });
    },
    handleClickCopy: function(e) {
        "" != this.data.currentPoem ? wx.setClipboardData({
            data: this.data.currentPoem,
            success: function(e) {
                wx.getClipboardData({
                    success: function(e) {
                        console.log(e.data), wx.showToast({
                            title: "复制成功"
                        });
                    }
                });
            }
        }) : wx.showModal({
            title: "提示",
            showCancel: !1,
            content: "请先点击生成藏头诗"
        });
    }
});